<?php
defined('IN_TS') or die('Access Denied.');
/* 
 * 课程管理
 */	

switch($ts){

	//课程列表
	case "list":
		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$url = SITE_URL.'index.php?app=study&ac=admin&mg=study&ts=list&page=';
		$lstart = $page*10-10;
		
		$arrStudy = $new['study']->findAll('study',null,'addtime desc',null,$lstart.',10');

		$studyNum = $new['study']->findCount('study');
		$pageUrl = pagination($studyNum, 10, $page, $url);

		include template("admin/study_list");
		
		break;
	
	//编辑
	case "edit":
		$studyid = $_GET['studyid'];
		
		$strStudy = $new['study']->find('study',array(
			'studyid'=>$studyid,
		));
		
		include template("admin/study_edit");
		break;
	
	//编辑执行
	case "edit":
		$studyid = $_POST['studyid'];
		
		$new['study']->update('study',array(
			'studyid'=>$studyid,
		),array(
			'studyname'		=> $_POST['studyname'],
			'studydesc'		=> $_POST['studydesc'],
			'userid'			=> $_POST['userid'],
		));
		
		qiMsg("修改成功！");
		break;
	
	//删除
	case "del":
		$studyid = intval($_GET['studyid']);
		
		
		$new['study']->delete('study',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->delete('study_learn',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->delete('study_lesson',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->delete('study_lesson_user',array(
			'studyid'=>$studyid,
		));
		
		$new['study']->delete('study_love',array(
			'studyid'=>$studyid,
		));
	
		
		qiMsg("课程删除成功！");
		
		break;
		
	//审核课程 
	case "isaudit":
	
		$studyid = $_GET['studyid'];
		
		$strStudy = $new['study']->find('study',array(
			'studyid'=>$studyid,
		));
		
		if($strStudy['isaudit']==1){
		
			$new['study']->update('study',array(
				'studyid'=>$studyid,
			),array(
				'isaudit'=>0,
			));
			
			qiMsg("课程审核通过成功");
		
		}
		
		if($strStudy['isaudit']==0){
		
			$new['study']->update('study',array(
				'studyid'=>$studyid,
			),array(
				'isaudit'=>1,
			));
			
			qiMsg("课程取消审核成功");
		
		}
		
		
		
		break;
	
	//推荐课程
	case "isrecommend":
		$studyid = $_GET['studyid'];
		
		$strStudy = $new['study']->find('study',array(
			'studyid'=>$studyid,
		));
		
		if($strStudy['isrecommend']==0){
		
			$new['study']->update('study',array(
				'studyid'=>$studyid,
			),array(
				'isrecommend'=>1,
			));
			
			qiMsg("课程推荐成功");
		
		}
		
		if($strStudy['isrecommend']==1){
		
			$new['study']->update('study',array(
				'studyid'=>$studyid,
			),array(
				'isrecommend'=>0,
			));
			
			qiMsg("课程取消推荐成功");
		
		}
		
		break;
		
	case "deleteuser":
		$userid = intval($_POST['userid']);
		
		$new['study']->delete('study',array('userid'=>$userid));
		$new['study']->delete('study_learn',array('userid'=>$userid));
		$new['study']->delete('study_lesson_comment',array('userid'=>$userid));
		$new['study']->delete('study_love',array('userid'=>$userid));
		
		aac('user')->toEmpty($userid);
		
		qiMsg('删除成功！');
		
		break;
}